/*
 * 文  件   名: MessageConvert.java
 * 版         本: docrepository-web(Anttribe). All rights reserved
 * 描         述: <描述>
 * 修   改  人: zhaoyong
 * 修改时 间: 2014年11月20日
 */
package org.anttribe.docrepository.web.message.convert;

import java.util.ArrayList;
import java.util.List;

import org.anttribe.docrepository.message.domain.Message;
import org.anttribe.docrepository.user.domain.UserInfo;
import org.anttribe.docrepository.web.message.vo.MessageVo;
import org.anttribe.saturn.common.utils.ObjectUtils;
import org.apache.commons.collections.CollectionUtils;

/**
 * Message与Vo对象的转换器
 * 
 * @author zhaoyong
 * @version 2014年11月20日
 */
public class MessageConvert
{
    /**
     * 将BO对象转换成VO
     * 
     * @param bo BO对象
     * @return MessageVo
     * @see [类、类#方法、类#成员]
     */
    public MessageVo convertToVo(Message bo)
    {
        MessageVo vo = null;
        if (!ObjectUtils.isNullOrNone(bo))
        {
            vo = new MessageVo();
            vo.setMessageId(bo.getMessageId());
            vo.setTitle(bo.getTitle());
            vo.setContent(bo.getContent());
            vo.setSendTime(bo.getSendTime());
            vo.setHasRead(vo.isHasRead());
            
            UserInfo sender = bo.getSender();
            if (!ObjectUtils.isNullOrNone(sender))
            {
                vo.setSenderId(sender.getUserId());
                vo.setSenderName(sender.getUsername());
            }
            
            UserInfo receiver = bo.getReceiver();
            if (!ObjectUtils.isNullOrNone(receiver))
            {
                vo.setReceiverId(receiver.getUserId());
                vo.setReceiverName(receiver.getUsername());
            }
        }
        return vo;
    }
    
    /**
     * 将BO对象转换成VO
     * 
     * @param boList List<Message>
     * @return List<MessageVo>
     */
    public List<MessageVo> convertToVo(List<Message> boList)
    {
        List<MessageVo> voList = null;
        if (!CollectionUtils.isEmpty(boList))
        {
            voList = new ArrayList<MessageVo>();
            for (Message bo : boList)
            {
                voList.add(convertToVo(bo));
            }
        }
        return voList;
    }
}